﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DesignPattern.CompositePattern
{
    //定义中间树枝
    public class Composite:Component
    {
        public Composite(string name)
            : base(name)
        {
        }
        //子节点
        private List<Component> _children = new List<Component>();
        public override void Add(Component c)
        {
            _children.Add(c);
        }

        public override void Remove(Component c)
        {
            _children.Remove(c);
        }

        public override void Display(int dep)
        {
            Console.WriteLine(new String('-', dep) + _name);

            foreach (var item in _children)
            {
                item.Display(dep + 2);
            }
        }
    }
}
